package org.gesplan.ui;

import java.awt.EventQueue;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.beans.Beans;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import javax.persistence.Query;
import javax.swing.JFrame;
import org.gesplan.controller.GenericController;
import org.gesplan.entity.Section;
import org.gesplan.entity.Staff;
import org.gesplan.util.ExcelManager;
import org.gesplan.util.RefreshWorker;
import org.gesplan.util.Utils;
import org.jdesktop.observablecollections.ObservableCollections;
import org.jdesktop.swingbinding.JTableBinding;


/**
 *
 * @author David
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public class RptStaffHoursPanel extends AbstractPanel {

    private JTableBinding jTableBinding;
    private boolean isLoaded = false;
    private Date dateStart = null;
    private Date dateEnd = null;
    private Section section = null;
    private Staff staff = null;
    

    public RptStaffHoursPanel() {
        
        super();
        try {
            initComponents();
        } catch (Exception e) {
            logger.log(Level.SEVERE, bundle.getString("ERROR_DB_CONNECTION"), e);
        }
        if (!Beans.isDesignTime()) {
            initConfig();
        }

        this.addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                if (HierarchyEvent.SHOWING_CHANGED == (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED)) {
                    isLoaded = true;
                    changeFilter();
                }
            }
        });

    }


    @SuppressWarnings("deprecation")
    private void initConfig() {

        super.abstractTable = masterTable;
        super.abstractQuery = query1;
        super.abstractList = list1;

        // Initialize filter dates
        Date dateIni = new Date();
        int year = dateIni.getYear();
        dateEndDateChooser.setDate(dateIni);
        Date dateAux = new Date(year, 0, 1);
        dateStartDateChooser.setDate(dateAux);

        GenericController.fillComboBox(bundle.getString("qryStaff"), filterStaffComboBox);
        filterStaffComboBox.setSelectedIndex(-1);
        GenericController.fillComboBox(bundle.getString("qrySection"), filterSectionComboBox);
        filterSectionComboBox.setSelectedIndex(-1);
        
        initSorter();
        setHeaders();

    }

    
    private void setHeaders() {
        Utils.setTableHeader(masterTable);
        masterTable.getColumnModel().getColumn(0).setPreferredWidth(150);
        masterTable.getColumnModel().getColumn(1).setPreferredWidth(70);
        masterTable.getColumnModel().getColumn(2).setPreferredWidth(70);
        for (int i = 3; i <= 9; i++) {
            masterTable.getColumnModel().getColumn(i).setPreferredWidth(50);
        }
    }
    

    private void changeFilter() {

        if (isLoaded) {
            // Get Filters
            try {
                dateStart = dateStartDateChooser.getDate();
                dateEnd = dateEndDateChooser.getDate();
                section = (Section) filterSectionComboBox.getSelectedItem();                
                staff = (Staff) filterStaffComboBox.getSelectedItem();
            } catch (ClassCastException ex) {
                logger.warning(ex.getMessage());
            }

            // Build JQL Query
            String jql = "SELECT o FROM RptStaffHours o ";
            String where = null;
            if (staff != null) {
                where = "WHERE ";
                where += "o.staffId.id = " + staff.getId();
            }
            if (where != null) {
                jql += where;
            }
            jql += " ORDER BY o.dateStart";
            updateTableBinding(jql);
        }

    }


    private void updateTableBinding(String jql) {
        if (!Beans.isDesignTime()) {
            query1 = entityManager.createQuery(jql);
            list1 = ObservableCollections.observableList(query1.getResultList());
            jTableBinding.unbind();
            jTableBinding.setSourceObject(list1);
            jTableBinding.bind();
            masterScrollPane.setViewportView(masterTable);
            setHeaders();
        }
    }


    private void resetFilters() {
        dateStartDateChooser.setDate(null);
        dateEndDateChooser.setDate(null);
        filterSectionComboBox.setSelectedIndex(-1);
        filterStaffComboBox.setSelectedIndex(-1);
        section = null;
        staff = null;
        dateStart = null;
        dateEnd = null;
    }


    private void calculateStaffHours() {
        
        String sql = "DELETE FROM var.rpt_staff_hours";
        String where = null;
        try {
            Statement st = Utils.getConnection().createStatement();
            st.execute(sql);
            sql = "INSERT INTO var.rpt_staff_hours";
            sql += " SELECT staff_id, '" + Utils.dateToString(dateStart) + "', '" + Utils.dateToString(dateEnd) + "',";
            sql += " SUM(worked) as worked, SUM(extra_to_charge) as extra_to_charge, SUM(extra_to_recover) as extra_to_recover, SUM(extra_recovered) as extra_recovered, "
                + "SUM(vacation) as vacation, SUM(disable) as disable, SUM(syndicate) as syndicate, SUM(formation) as formation";
            sql += " FROM work ";
            if (dateStart != null) {
                where = "WHERE ";
                where += "date_work >= '" + Utils.dateToString(dateStart) + "'";
            }
            if (dateEnd != null) {
                where = (where == null) ? "WHERE " : where + " AND ";
                where += "date_work <= '" + Utils.dateToString(dateEnd) + "'";
            }
            if (section != null) {
                where = (where == null) ? "WHERE " : where + " AND ";
                where += "section_id = " + section.getId() ;
            }            
            if (where != null) {
                sql += where;
            }
            sql += " GROUP BY staff_id";
            st.execute(sql);
            if (filterStaffComboBox.getSelectedIndex() != -1){
                filterStaffComboBox.setSelectedIndex(-1);
            }
            else{
                changeFilter();
            }
            refresh(query1, list1);            
        } catch (SQLException ex) {
            logger.severe(ex.getMessage());
        }
        
    }

    
    private void prepareReport(){
        
        String where = null;
        if (dateStart != null) {
            where = "WHERE ";
            where += "data >= '" + Utils.dateToString(dateStart) + "'";
        }
        if (dateEnd != null) {
            where = (where == null) ? "WHERE " : where + " AND ";
            where += "data <= '" + Utils.dateToString(dateEnd) + "'";
        }
        if (section != null) {
            where = (where == null) ? "WHERE " : where + " AND ";
            where += "section_id = " + section.getId();
        }    
        if (staff != null) {
            where = (where == null) ? "WHERE " : where + " AND ";
            where += "staff_id = " + staff.getId();
        }        
        ExcelManager.reportWork(where);
        
    }
  
    
    @Override
    protected void refresh(Query queryParam, List<?> listObject) {
        refreshWorker = new RefreshWorker(this, entityManager, queryParam, listObject);
        refreshWorker.execute();
    }
    

    // <editor-fold defaultstate="collapsed" desc="Auto Generated Code">      
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        staffQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery(bundle.getString("qryStaff"));
        staffList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : staffQuery.getResultList();
        query1 = Beans.isDesignTime() ? null : entityManager.createQuery("SELECT o FROM RptStaffHours o");
        list1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : query1.getResultList();
        sectionQuery = Beans.isDesignTime() ? null : entityManager.createQuery(bundle.getString("qrySection"));
        sectionList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : sectionQuery.getResultList();
        masterScrollPane = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        filterStaffComboBox = new javax.swing.JComboBox();
        staffIdLabel1 = new javax.swing.JLabel();
        dateStartDateChooser = new com.toedter.calendar.JDateChooser();
        staffIdLabel2 = new javax.swing.JLabel();
        staffIdLabel3 = new javax.swing.JLabel();
        dateEndDateChooser = new com.toedter.calendar.JDateChooser();
        resetButton = new javax.swing.JButton();
        calculateButton = new javax.swing.JButton();
        reportButton = new javax.swing.JButton();
        filterSectionComboBox = new javax.swing.JComboBox();
        staffIdLabel4 = new javax.swing.JLabel();

        FormListener formListener = new FormListener();

        setName("prova"); // NOI18N

        masterTable.setAutoCreateRowSorter(true);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list1, masterTable, "bindingTable");
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${staffId}"));
        columnBinding.setColumnName("Treballador");
        columnBinding.setColumnClass(org.gesplan.entity.Staff.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dateStart}"));
        columnBinding.setColumnName("Data Inici");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dateEnd}"));
        columnBinding.setColumnName("Data Fi");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${worked}"));
        columnBinding.setColumnName("Treballades");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${extraToCharge}"));
        columnBinding.setColumnName("A Cobrar");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${extraToRecover}"));
        columnBinding.setColumnName("A Recuperar");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${extraRecovered}"));
        columnBinding.setColumnName("Recuperades");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vacation}"));
        columnBinding.setColumnName("Vacances");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${disable}"));
        columnBinding.setColumnName("Baixa");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${syndicate}"));
        columnBinding.setColumnName("Sindicals");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${formation}"));
        columnBinding.setColumnName("Formació");
        columnBinding.setColumnClass(Float.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        masterTable.addPropertyChangeListener(formListener);
        masterScrollPane.setViewportView(masterTable);
        this.jTableBinding = jTableBinding;

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, staffList, filterStaffComboBox, "bindFilterStaff");
        bindingGroup.addBinding(jComboBoxBinding);

        filterStaffComboBox.addActionListener(formListener);

        staffIdLabel1.setText("Treballador:");

        dateStartDateChooser.setToolTipText("dd-mm-yyyy"); // NOI18N
        dateStartDateChooser.setDateFormatString("dd-MM-yyyy");
        dateStartDateChooser.addPropertyChangeListener(formListener);

        staffIdLabel2.setLabelFor(dateStartDateChooser);
        staffIdLabel2.setText("Des de:");

        staffIdLabel3.setLabelFor(dateEndDateChooser);
        staffIdLabel3.setText("Fins:");

        dateEndDateChooser.setDateFormatString("dd-MM-yyyy");
        dateEndDateChooser.addPropertyChangeListener(formListener);

        resetButton.setMnemonic('R');
        resetButton.setText(bundle.getString("RESET")); // NOI18N
        resetButton.addActionListener(formListener);

        calculateButton.setMnemonic('R');
        calculateButton.setText("Calcular");
        calculateButton.addActionListener(formListener);

        reportButton.setMnemonic('R');
        reportButton.setText("Informe");
        reportButton.addActionListener(formListener);

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, sectionList, filterSectionComboBox);
        bindingGroup.addBinding(jComboBoxBinding);

        filterSectionComboBox.addActionListener(formListener);

        staffIdLabel4.setText("Secció:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(staffIdLabel2)
                                        .addGap(31, 31, 31))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(staffIdLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(staffIdLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 3, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(dateStartDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(staffIdLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(dateEndDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(filterSectionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(filterStaffComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(31, 31, 31)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(calculateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(reportButton, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(resetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(0, 180, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(masterScrollPane)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(dateStartDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dateEndDateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(staffIdLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(staffIdLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(calculateButton)
                    .addComponent(reportButton)
                    .addComponent(filterSectionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(staffIdLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(resetButton)
                    .addComponent(filterStaffComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(staffIdLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener, java.beans.PropertyChangeListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == filterStaffComboBox) {
                RptStaffHoursPanel.this.filterStaffComboBoxActionPerformed(evt);
            }
            else if (evt.getSource() == resetButton) {
                RptStaffHoursPanel.this.resetButtonActionPerformed(evt);
            }
            else if (evt.getSource() == calculateButton) {
                RptStaffHoursPanel.this.calculateButtonActionPerformed(evt);
            }
            else if (evt.getSource() == reportButton) {
                RptStaffHoursPanel.this.reportButtonActionPerformed(evt);
            }
            else if (evt.getSource() == filterSectionComboBox) {
                RptStaffHoursPanel.this.filterSectionComboBoxActionPerformed(evt);
            }
        }

        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            if (evt.getSource() == masterTable) {
                RptStaffHoursPanel.this.masterTablePropertyChange(evt);
            }
            else if (evt.getSource() == dateStartDateChooser) {
                RptStaffHoursPanel.this.dateStartDateChooserPropertyChange(evt);
            }
            else if (evt.getSource() == dateEndDateChooser) {
                RptStaffHoursPanel.this.dateEndDateChooserPropertyChange(evt);
            }
        }
    }// </editor-fold>//GEN-END:initComponents


    public static void main(String[] args) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(RptStaffHoursPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(RptStaffHoursPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(RptStaffHoursPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(RptStaffHoursPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame();
                frame.setContentPane(new RptStaffHoursPanel());
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.pack();
                frame.setVisible(true);
            }
        });
    }
    // </editor-fold>          

    private void filterStaffComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filterStaffComboBoxActionPerformed
        changeFilter();
    }//GEN-LAST:event_filterStaffComboBoxActionPerformed

    private void dateStartDateChooserPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dateStartDateChooserPropertyChange
        changeFilter();
    }//GEN-LAST:event_dateStartDateChooserPropertyChange

    private void dateEndDateChooserPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dateEndDateChooserPropertyChange
        changeFilter();
    }//GEN-LAST:event_dateEndDateChooserPropertyChange

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
        resetFilters();
    }//GEN-LAST:event_resetButtonActionPerformed

    private void masterTablePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_masterTablePropertyChange
        Utils.setRecordInfo(masterTable);
    }//GEN-LAST:event_masterTablePropertyChange

    private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateButtonActionPerformed
        calculateStaffHours();
    }//GEN-LAST:event_calculateButtonActionPerformed

    private void reportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reportButtonActionPerformed
        prepareReport();
    }//GEN-LAST:event_reportButtonActionPerformed

    private void filterSectionComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filterSectionComboBoxActionPerformed
        changeFilter();
    }//GEN-LAST:event_filterSectionComboBoxActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton calculateButton;
    private com.toedter.calendar.JDateChooser dateEndDateChooser;
    private com.toedter.calendar.JDateChooser dateStartDateChooser;
    private javax.swing.JComboBox filterSectionComboBox;
    private javax.swing.JComboBox filterStaffComboBox;
    private java.util.List<org.gesplan.entity.RptStaffHours> list1;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JTable masterTable;
    private javax.persistence.Query query1;
    private javax.swing.JButton reportButton;
    private javax.swing.JButton resetButton;
    private java.util.List<org.gesplan.entity.Section> sectionList;
    private javax.persistence.Query sectionQuery;
    private javax.swing.JLabel staffIdLabel1;
    private javax.swing.JLabel staffIdLabel2;
    private javax.swing.JLabel staffIdLabel3;
    private javax.swing.JLabel staffIdLabel4;
    private java.util.List<org.gesplan.entity.Staff> staffList;
    private javax.persistence.Query staffQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}